<?php

namespace Hdphim\Modules\User\Controllers;

use Phalcon\Mvc\Controller as Controller;
use Hdphim\Modules\User\Forms\SignUpForm;

class UserController extends Controller
{
    public function indexAction()
    {
        
    }
    
    public function loginAction()
    {
       
    }
    
    public function signupAction()
    {
        $form = new SignUpForm();
        if($this->request->isPost())
        {
            if($form->isValid($this->request->getPost()) != false)
            {
                $user = new Users();
                $user->assign(array(
                    'name' => $this->request->getPost('name' , 'striptags'),
                    'email' => $this->request->getPost('email'),
                    'password' => $this->security->hash($this->request->getPost('password')),
                    'profilesId' => 2
                ));
                
                if($user->save())
                {
                	
                    return $this->dispatcher->forward(array(
                        'controller' => 'index',
                        'action' => 'index'
                    ));
                }
                $this->flash->error($user->getMessages());
            }
        }

        $this->view->form = $form;
    }
}
